<?php

namespace App\Admin\Controllers;

class NoticeController extends Controller{
   // 通知列表
    public function index(){
        $notices = \App\Notice::paginate(5);
        return view('admin.notice.index',compact('notices'));
    }
    // 创建通知
    public function create(){
        return view('admin.notice.add');
    }
    // 创建行为
    public function store(){
        $this->validate(request(),[
            'title' => 'required|string',
            'content' => 'required|string',
        ]);
        $notice = \App\Notice::create(request(['title','content']));
        dispatch(new \App\Jobs\SendMessage($notice));//通知创建后 加入到队列中
        return redirect('/admin/notices');
    }
    // 删除专题
    public function destroy(\App\Notice $notice){
        $notice->delete();
        return [
            'status'=> 0,
            'msg' =>'通知删除成功!',
        ];
    }
}